package com.nifostasky.comic.controller;

import com.nifostasky.comic.entitys.SysUnit;
import com.nifostasky.comic.service.SysUnitService;
import com.nifostasky.comic.utils.PageUtils;
import com.nifostasky.comic.vos.JsonResult;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUnit")
@Api(tags = "单位控制层")
@AllArgsConstructor
public class SysUnitController {
    private SysUnitService sysUnitService;

    @ApiOperation(value = "分页列表",notes = "带参分页查询列表")
    @GetMapping("findListPage")
    @ApiOperationSupport(order = 1)
    public JsonResult findListPage(PageUtils pageUtils, SysUnit sysUnit){
        return new JsonResult(sysUnitService.findListPage(pageUtils, sysUnit));
    }
    @ApiOperation(value = "不分页列表",notes = "带参查询列表")
    @GetMapping("findList")
    @ApiOperationSupport(order = 5)
    public JsonResult findList(SysUnit sysUnit){
        return new JsonResult(sysUnitService.findList(sysUnit));
    }
    @ApiOperation("新增/修改")
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 2)
    public JsonResult saveOrUpdate(@RequestBody SysUnit sysUnit){
        return new JsonResult(sysUnitService.saveOrUpdateUnit(sysUnit));
    }

    @ApiOperation("根据主键id获取信息")
    @GetMapping("/getData")
    @ApiResponses(@ApiResponse(code = 200,message = "返回成功",response = SysUnit.class))
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "Int",required = true)
    )
    @ApiOperationSupport(order = 3)
    public JsonResult<SysUnit> getData(Long id){
        return new JsonResult(sysUnitService.getDataById(id));
    }


    @ApiOperation("单个或批量删除")
    @GetMapping("/deleteByIds")
    @ApiOperationSupport(order = 4)
    public JsonResult deleteByIds(@ApiParam("主键ids，批量删除时id用英文逗号隔开数据格式:id1,id2,id3,...") String ids){
        return new JsonResult(sysUnitService.deleteByIds(ids));
    }
}
